Skip to content

Harden assignment sync to prevent disappearing assignments#43

Open
digital-pro wants to merge 2 commits intomainfrom
fix-disappearing-assignment
Open

Harden assignment sync to prevent disappearing assignments#43
digital-pro wants to merge 2 commits intomainfrom
fix-disappearing-assignment

Conversation

@digital-pro
Copy link
Contributor

Summary

  • harden administration upsert payload handling to normalize org IDs, sanitize nested undefined fields, and validate required assessment fields before write
  • harden assignment fan-out write paths to sanitize assignment payloads immediately before transaction writes
  • add dedicated documentation of the disappearing-assignment issue, root cause categories, and mitigation strategy in functions/levante-admin/README_DISAPPEARING_ASSIGNMENTS.md

Issue context

Users reported that assignment creation could appear successful while one or more users were missing assignment docs. Investigation showed two categories:

  1. expected non-assignment due to assignment conditions (e.g., userType == student)
  2. true backend risk where malformed/undefined payload fields can break async fan-out writes

This PR addresses category (2) directly by preventing malformed data from reaching Firestore write paths.

What changed

functions/levante-admin/src/upsertAdministration.ts

  • normalize and dedupe org ID lists
  • recursively remove undefined fields from assessments/legal payloads
  • normalize assessment.params to object shape
  • validate required assessment keys (taskId, variantId, variantName)
  • reject invalid dates explicitly
  • preserve/guarantee non-empty createdBy on updates

functions/levante-admin/src/assignments/assignment-utils.ts

  • use cleaned assessments when building assignment docs
  • sanitize assignment payloads before transaction.set(...) in add/update fan-out paths

functions/levante-admin/src/utils/utils.ts

  • update removeUndefinedFields() to recursively clean nested arrays (not only top-level undefined entries)

Documentation

  • added functions/levante-admin/README_DISAPPEARING_ASSIGNMENTS.md with:
    • issue summary
    • root-cause split (expected non-assignment vs real fan-out failure)
    • fix rationale
    • operational recommendations

Why this should fix the issue

Assignment fan-out (updateAssignmentsForOrgChunk) is asynchronous and can fail on malformed write payloads. This patch sanitizes and validates data both at ingress (upsertAdministration) and immediately before assignment writes, reducing partial/failed propagation caused by undefined and malformed fields.

Test plan

  • verified lint diagnostics for touched files (no IDE lint issues on changed files)
  • reproduced and analyzed assignment behavior against live environment
  • run full workspace TS build in CI environment with all workspace deps installed
  • run emulator integration pass focused on administration upsert + assignment fan-out

Related support-side change

levante-support bug-806 test update was pushed directly to main to align test expectations with assignment conditions and keep assignment audit artifacts.

Made with Cursor

digital-pro and others added 2 commits February 9, 2026 17:04
Normalize and validate administration data before persistence, sanitize assignment write payloads in fan-out paths, and document the disappearing-assignment issue with root cause and mitigation details.

Co-authored-by: Cursor <cursoragent@cursor.com>
Keep only the functional disappearing-assignment hardening changes and drop formatting-only edits from touched files.

Co-authored-by: Cursor <cursoragent@cursor.com>
@CCuskley CCuskley requested a review from asengupta3 February 10, 2026 14:15
Copy link
Collaborator

@asengupta3 asengupta3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a partial solution. I think the main issue is the async operation that you have mentioned in the README. Also, we should not be committing README's for every bug. They should be a part of the issue description. Please look at this PR:
#20
and the comments there. I think the real solution is to get that PR working and merged. That should give us more clarity and more accuracy.

@digital-pro
Copy link
Contributor Author

Chrissy and Amy were having a hard time recreating this task so I wrote a batch tester to run their scenario a bunch and get it to fail. Then I had the test generate a fix and document it. I posted that on the channel, but didn't document it here. The idea was that someone could take a look at this as POC and build from there. No intention to checkin the README, for starters. Just there as a reference for whomever knows enough to do the right thing. I need to make that more clear in the name of the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants